﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace NumSkull
{
    public static class Utility
    {
        public static bool IsNullOrEmpty(this IEnumerable<double> data)
        {
            if (data == null) return true;

            var collection = data as ICollection<double>;
            if (collection != null) return collection.Count < 1;

            return data.IsEmpty();
        }

        public static bool IsEmpty(this IEnumerable<double> data)
        {
            var result = !data.Any();
            return result;
        }

        public static void ForEach(this IEnumerable<double> data, Action<double> action)
        {
            foreach (var item in data)
            {
                action(item);
            }
        }

        public static IEnumerable<double> SteppedRange(double start, int count, double step)
        {
            double max = start + (count * step) - 1;
            if (count < 0 || max > double.MaxValue) throw new ArgumentOutOfRangeException("count");

            return SteppedRangeIterator(start, count, step);
        }

        private static IEnumerable<double> SteppedRangeIterator(double start, double count, double step)
        {
            for (int i = 0; i <= count; i++)
            {
                yield return start + (i * step);
            }
        }
    }
}
